<template>
	<view>
        <view class="logo">
			<view class="img">
				<image src="../../static/logo.png" mode="widthFix"></image>
			</view>
		</view>
		<view class="form re">
			<view class="username">
				<!-- <view class="get-code" :style="{'color':getCodeBtnColor}" @click.stop="getCode()">{{getCodeText}}</view> -->
				<input placeholder="请输入姓名" v-model="au_name" placeholder-style="color: rgba(255,255,255,0.8);"/>
			</view>
			<view class="code">
				<input placeholder="请输入电话" v-model="au_tel" placeholder-style="color: rgba(255,255,255,0.8);"/>
			</view>
			<view class="username" style="display: none;">
				<input placeholder="请输入用户名" v-model="au_username" placeholder-style="color: rgba(255,255,255,0.8);"/>
			</view>
			<view class="password">
				<input placeholder="请输入密码" v-model="au_pwd" password=true placeholder-style="color: rgba(255,255,255,0.8);"/>
			</view>
			<view class="password">
				<input placeholder="请确认密码" v-model="au_pwd2" password=true placeholder-style="color: rgba(255,255,255,0.8);"/>
			</view>
			<view class="btn" @tap="doReg">立即注册</view>
			<view class="res">
				<view @tap="toLogin">已有账号立即登录</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	// import md5 from "@/common/SDK/md5.min.js";
	export default {
		data() {
			return {
				au_name:'',
				au_tel:'',
				au_username:'',
				au_pwd:'',
				au_pwd2:'',  //确认密码
				
				phoneNumber:"",
				code:'',
				passwd:"",
				getCodeText:'获取验证码',
				getCodeBtnColor:"#ffffff",
				getCodeisWaiting:false
			}
		},
		onLoad() {

		},
		methods: {
			Timer(){},
			getCode(){
				uni.hideKeyboard()
				if(this.getCodeisWaiting){
					return ;
				}
				if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneNumber))){ 
					uni.showToast({title: '请填写正确手机号码',icon:"none"});
					return false; 
				} 
				
				
				this.getCodeText = "发送中..."
				this.getCodeisWaiting = true;
				this.getCodeBtnColor = "rgba(255,255,255,0.5)"
				//示例用定时器模拟请求效果
				setTimeout(()=>{
					uni.showToast({title: '验证码已发送',icon:"none"});
					//示例默认1234，生产中请删除这一句。
					this.code=1234;
					this.setTimer();
				},1000)
			},
			setTimer(){
				let holdTime = 60;
				this.getCodeText = "重新获取(60)"
				this.Timer = setInterval(()=>{
					if(holdTime<=0){
						this.getCodeisWaiting = false;
						this.getCodeBtnColor = "#ffffff";
						this.getCodeText = "获取验证码"
						clearInterval(this.Timer);
						return ;
					}
					this.getCodeText = "重新获取("+holdTime+")"
					holdTime--;
					
				},1000)
			},
			doReg(){
				uni.hideKeyboard()
				//模板示例部分验证规则
				if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.au_tel))){ 
					uni.showToast({title: '请填写正确手机号码',icon:"none"});
					return false; 
				} 
				
				if(this.au_name.length > 20){
					uni.showToast({title: '姓名长度太长，请重新输入',icon:"none"});
					return false; 
				}
				
				if(this.au_name === ''){
					uni.showToast({title: '请填写名字',icon:"none"});
					return false; 
				}
				
				if(this.au_pwd.length > 20 || this.au_pwd.length < 6){
					uni.showToast({title: '密码长度必须为6-20',icon:"none"});
					return false; 
				}
				
				if(this.au_pwd != this.au_pwd2){
					uni.showToast({title: '两次密码输入不一致',icon:"none"});
					return false; 
				}
				
				
				
				this.au_username = this.au_tel
				
				let that = this
				uni.request({
					url: that.$title + 'AppUser/GetAppUserCode',
					headers: {},
					success: (res) => {
						if(res.data.status === 200){
							let data = {
								"plp_usercode":res.data.data,
								"au_name": that.au_name,
								"au_tel": that.au_tel,
								"au_username": that.au_username,
								"au_pwd": that.au_pwd,
							}
							
							uni.request({
								url: that.$title + 'AppUser/AddAppUserInfo',
								data: data,
								success: (res) => {
									if(res.data.status === 200){
										uni.showToast({
											icon: "none",
											title: '注册成功'
										})
										uni.redirectTo({
										    url: '../login/login'
										});
									}else{
										uni.showToast({
											icon: "none",
											title: res.data.message
										})
									}
								}
							});
						} else {
							uni.showToast({
								icon: "none",
								title: res.data.message
							})
						}
					}
				});
				
				// uni.request({
				// 	url: '/api/v1/AddAppUserInfo',
				// 	data: data,
				// 	success: (res) => {
				// 		
				// 		if(res.data.status === 200){
				// 			// uni.redirectTo({
				// 			//     url: '../view/main'
				// 			// });
				// 		}else{
				// 			uni.showToast({
				// 				icon: "none",
				// 				title: res.data.message
				// 			})
				// 		}
				// 	}
				// });
				
			},
			toLogin(){ 
				uni.hideKeyboard()
				uni.redirectTo({url: 'login'});
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss">
	@import "../../static/css/login.scss";
</style>
